//
//  HJNewsModel.m
//  KaiChat
//
//  Created by lx on 2023/12/22.
//

#import "HJNewsModel.h"

@implementation HJNewsModel

MJLogAllIvars

+ (HJNewsModel *)modelWithMessageModel:(HJChatMessageModel *)messageModel {
    NSDictionary *msgDict = [messageModel.msg mj_JSONObject];
    NSDictionary *dict = msgDict[@"content"];
    if (![dict isKindOfClass:NSDictionary.class]) return nil;
    
    HJNewsModel *model = [[HJNewsModel alloc] init];
    model.coverUrl = dict[@"cover"];
    model.title = dict[@"title"];
    model.desc = dict[@"desc"];
    model.associationmMsgId = messageModel.associationmMsgId;
    model.timestamp = messageModel.timestamp;
    model.detailUrl = dict[@"url"];
    model.newsId = dict[@"id"];
    UIFont *descFont = UIFontMake(12);
    CGSize textSize = [model.desc getStringSizeWithWidth:KScreenWidth - leftRightMargin * 2 - 30 font:descFont];
    textSize = CGSizeMake(ceil(textSize.width), ceil(textSize.height));
    CGFloat textMaxH = ceil(descFont.lineHeight * 2);
    if (textSize.height > textMaxH) {
        textSize.height = textMaxH;
    }
    model.height = textSize.height + 196 + 15;
    return model;
}

@end

 
//
//2023-12-26 19:07:08.981904+0800 KaiChat[54543:2064703] didReceiveMessageWithData = {
//    session_id = 11000;
//    op = 3000;
//    picture = <null>;
//    system_msg_typ = 0;
//    burn_duration = 0;
//    voice = <null>;
//    typ = 11000;
//    rcv_uid = 0;
//    sender_pic = https://img-fs-dev.s3.ap-southeast-1.amazonaws.com/bitchat/1/public-kai-news.png;
//    seq_id = 497469140160581;
//    send_time_srv = 1703588828797;
//    wallet_transfer = <null>;
//    chat_type = 3;
//    send_uid = 11000;
//    is_burn = 0;
//    sender_name = kai news;
//    client_msg_id = 0;
//    send_time_client = 0;
//    association_msg_id = 1;
//    msg = {
//    content = {"id":1,"created_at":1703211019,"updated_at":0,"deleted_at":0,"template_code":"132434","title":"test","author":"test","cover":"https://img-fs-dev.s3.ap-southeast-1.amazonaws.com/bitchat/1/20231222/2/444015586140293/7f9d24d6046e6299e05eddddb7222443.jpg","desc":"test","content":"","url":"https://www.baidu.com"};
//}
//;
//}
//2023-12-26 19:07:10.902645+0800 KaiChat[54543:2064703] didReceiveMessageWithData = {
//    session_id = 11000;
//    op = 3000;
//    picture = <null>;
//    system_msg_typ = 0;
//    burn_duration = 0;
//    voice = <null>;
//    typ = 11000;
//    rcv_uid = 0;
//    sender_pic = https://img-fs-dev.s3.ap-southeast-1.amazonaws.com/bitchat/1/public-kai-news.png;
//    seq_id = 497469140160581;
//    send_time_srv = 1703588828797;
//    wallet_transfer = <null>;
//    chat_type = 3;
//    send_uid = 11000;
//    is_burn = 0;
//    sender_name = kai news;
//    client_msg_id = 0;
//    send_time_client = 0;
//    association_msg_id = 1;
//    msg = {
//    content = {"id":1,"created_at":1703211019,"updated_at":0,"deleted_at":0,"template_code":"132434","title":"test","author":"test","cover":"https://img-fs-dev.s3.ap-southeast-1.amazonaws.com/bitchat/1/20231222/2/444015586140293/7f9d24d6046e6299e05eddddb7222443.jpg","desc":"test","content":"","url":"https://www.baidu.com"};
//}
//;
//}
